/*
 * @Descripttion: Descripttion
 * @Author: LiLei
 * @Date: 2024-04-17 14:52:56
 * @LastEditors: LiLei
 * @LastEditTime: 2024-04-28 21:17:35
 */
import {
  defineConfig
} from "vite"
import vue from "@vitejs/plugin-vue"
const {
  resolve
} = require("path")
import vueJsx from "@vitejs/plugin-vue-jsx"
import viteCompression from "vite-plugin-compression"
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    viteCompression({
      verbose: false, // 不显示gzip压缩信息
      threshold: 1024 * 10, // 10kb
    }),
  ],
  server: {
    //本地服务器主机名 配置后可以使用本地网络访问
    host: "0.0.0.0",
    //指定启动端口号
    port: 8088,
    //设为 true 时若端口已被占用则会直接退出，而不是尝试下一个可用端口
    strictPort: false,
    //服务器启动时自动在浏览器中打开应用程序,当此值为字符串时，会被用作 URL 的路径名
    open: true,
    proxy: {
      "/api": {
        target: "https://web.abc.com/api",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  define: {
    'process.env': {
      BASE_API: '',
    },
  },
  base: "./",
  build: {

    outDir: "dist",
    assetsDir: "assets", //指定静态资源存放路径
    sourcemap: false, //是否构建source map 文件
    minify: "terser", //构建时开启terser压缩
    terserOptions: {
      // 生产环境移除console
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
  resolve: {
    alias: [{
      find: "@",
      replacement: resolve(__dirname, "src"),
    },
    {
      find: "assets",
      replacement: resolve(__dirname, "src/assets"),
    },
    {
      find: "vue",
      replacement: "vue/dist/vue.esm-bundler.js", // compile template
    },
    ],
    extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  },
})